import { getAddressApi } from '../../api/address'
const addressStore = {
  state: {
    addressList: [],//地址列表
    defAddress: {},//默认地址
  },
  getters: {
    addressList: state => state.addressList,
    defAddress: state => state.defAddress
  },
  mutations: {
    changeData (state, res) {
      state.addressList = res.data;
      res.data.forEach(element => {
        element.tel = element.phone;
        if (element.def == "1") {
          state.defAddress = element; //赋值地址
        }
      });
    }
  },
  actions: {
    async getAddressAction ({ commit }) {
      var res = await getAddressApi()
      console.log("888888888888")
      console.log(res)
      commit("changeData", res)
    }
  },
  namespaced: true
}
export default addressStore